<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function(){
          var oTxt=document.getElementById('txt1');
          var oBtn=document.getElementById('btn1');
          var oUl=document.getElementById('ul1');
          oBtn.onclick=function(){
              var oLi=document.createElement('li');//先创建一个li
              oLi.innerHTML=oTxt.value;//再赋值
              oTxt.value='';
              if(oUl.children.length>0){
                  oUl.insertBefore(oLi,oUl.children[0]);
              }
             else{
                  oUl.appendChild(oLi);
              }
          };
        };
    </script>
</head>
<body>
<input type="text" id="txt1">
<input type="button" id="btn1" value="点击">
<ul id="ul1"></ul>
</body>
</html>